package com.migo.service.impl;

import com.migo.dao.MyTemplateCategoryDao;
import com.migo.dto.QueryMyTemplateProducerResultDTO;
import com.migo.dto.QueryMyTemplateResultDTO;
import com.migo.entity.MyTemplateCategoryEntity;
import com.migo.service.MyTemplateCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;



@Service("myTemplateCategoryService")
public class MyTemplateCategoryServiceImpl implements MyTemplateCategoryService {


	@Autowired
	private MyTemplateCategoryDao myTemplateCategoryDao;


	@Override
	public MyTemplateCategoryEntity queryObject(Integer id){
		return myTemplateCategoryDao.queryObject(id);
	}
	
	@Override
	public List<MyTemplateCategoryEntity> queryList(Map<String, Object> map){
		return myTemplateCategoryDao.queryList(map);
	}

	@Override
	public List<QueryMyTemplateResultDTO> queryMyTemplateList(Map<String, Object> map) {
		List<QueryMyTemplateResultDTO> resultList = new ArrayList<QueryMyTemplateResultDTO>();
		List<QueryMyTemplateResultDTO>  list = myTemplateCategoryDao.queryMyTemplateList(map);
		String lang="en";
		if(map.containsKey("lang")){

			lang = map.get("lang").toString();
		}
		if(list!=null ){
			for(QueryMyTemplateResultDTO temp:list){
				String id = temp.getId();
				QueryMyTemplateProducerResultDTO producer = myTemplateCategoryDao.queryProducer(id);
				temp.setProducer(producer);
				resultList.add(temp);
			}
		}else{
			return list;
		}
		return resultList;
	}
	/**
	 * 写死的制作者
	 * @param lang
	 * @return
	 */


	@Override
	public QueryMyTemplateResultDTO queryMyTemplateDetail(Map<String, Object> map) {
		return myTemplateCategoryDao.queryMyTemplateDetail(map);
	}

	@Override
	public int queryMyTemplateTotal(Map<String, Object> map) {
		return myTemplateCategoryDao.queryMyTemplateTotal(map);
	}

	@Override
	public int queryTotal(Map<String, Object> map){
		return myTemplateCategoryDao.queryTotal(map);
	}
	
	@Override
	public void save(MyTemplateCategoryEntity myTemplateCategory){
		myTemplateCategoryDao.save(myTemplateCategory);
	}
	
	@Override
	public void update(MyTemplateCategoryEntity myTemplateCategory){
		myTemplateCategoryDao.update(myTemplateCategory);
	}
	
	@Override
	public void delete(Integer id){
		myTemplateCategoryDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Integer[] ids){
		myTemplateCategoryDao.deleteBatch(ids);
	}
	
}
